<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>违规记录总览</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      padding: 0;
    }
    .container {
      width: 80%;
      margin: 50px auto;
      padding: 20px;
      background: #fff;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    h2 {
      text-align: center;
      color: #333;
    }
    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 20px;
    }
    th, td {
      padding: 12px;
      text-align: left;
      border-bottom: 1px solid #ddd;
    }
    th {
      background-color: #f2f2f2;
    }
    tr:hover {
      background-color: #f5f5f5;
    }
  </style>
</head>
<body>
<div class="container">
  <h2>违规记录总览</h2>
  <table id="recordsTable">
    <thead>
    <tr>
      <th>ID</th>
      <th>居民ID</th>
      <th>违规描述</th>
      <th>违规时间</th>
      <th>违规地点</th>
      <th>处理结果</th>
    </tr>
    </thead>
    <tbody>
    <!-- 违规记录数据将在这里动态插入 -->
    </tbody>
  </table>
</div>

<script>
  // 获取所有违规记录
  function fetchRecords() {
    fetch('http://localhost:8081/waste/api/violation/getAll')
            .then(response => response.json())
            .then(data => {
              const tableBody = document.querySelector('#recordsTable tbody');
              tableBody.innerHTML = ''; // 清空表格内容

              data.forEach(record => {
                const row = document.createElement('tr');
                row.innerHTML = `
                            <td>${record.vrId}</td>
                            <td>${record.vrResidentId}</td>
                            <td>${record.vrDescription}</td>
                            <td>${record.vrTime}</td>
                            <td>${record.vrLocation}</td>
                            <td>${record.vrResult}</td>
                        `;
                tableBody.appendChild(row);
              });
            })
            .catch(error => {
              alert('获取违规记录失败，请检查网络连接！');
              console.error('Error:', error);
            });
  }

  // 页面加载时调用
  window.onload = fetchRecords;
</script>
</body>
</html>